package com.lishem.rpc.server.service;

import com.lishem.common.annotation.RpcService;
import com.lishem.common.utils.RpcException;
import com.lishem.rpc.api.OrderService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@RpcService(cls = OrderService.class)
@Log4j2
public class OrderServiceImpl implements OrderService{

    @Value("${server.port}")
    private Integer serverPort;

    /**
     * 获取订单信息降级处理
     * @return
     */
    public String getOrderFallback(String userName, String orderNo) {
        log.info("enter getOrderFallback method.");
        return String.format("Server fallback(" + serverPort + "), param => userName: %s, orderNo: %s", userName, orderNo);
    }


    @Override
    public String getOrder(String userName, String orderNo) {
        if ("error".equalsIgnoreCase(userName)) {
            throw new RpcException("test exception! " + userName);
        }
        return String.format("Server(" + serverPort + "), Order Details => userName: %s, orderNo: %s", userName, orderNo);
    }
}